package com.ruoyi.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Qqandwechat;
import com.ruoyi.system.service.IQqandwechatService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 危险QQ/微信管理Controller
 *
 * @author ruoyi
 * @date 2022-09-23
 */
@Controller
@RequestMapping("/system/qqandwechat")
public class QqandwechatController extends BaseController {
    private String prefix = "system/qqandwechat";

    @Autowired
    private IQqandwechatService qqandwechatService;

    @RequiresPermissions("system:qqandwechat:view")
    @GetMapping()
    public String qqandwechat() {
        return prefix + "/qqandwechat";
    }

    /**
     * 查询危险QQ/微信管理列表
     */
    @RequiresPermissions("system:qqandwechat:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Qqandwechat qqandwechat) {
        startPage();
        List<Qqandwechat> list = qqandwechatService.selectQqandwechatList(qqandwechat);
        return getDataTable(list);
    }

    /**
     * 导出危险QQ/微信管理列表
     */
    @RequiresPermissions("system:qqandwechat:export")
    @Log(title = "危险QQ/微信管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Qqandwechat qqandwechat) {
        List<Qqandwechat> list = qqandwechatService.selectQqandwechatList(qqandwechat);
        ExcelUtil<Qqandwechat> util = new ExcelUtil<Qqandwechat>(Qqandwechat.class);
        return util.exportExcel(list, "危险QQ/微信管理数据");
    }

    /**
     * 新增危险QQ/微信管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存危险QQ/微信管理
     */
    @RequiresPermissions("system:qqandwechat:add")
    @Log(title = "危险QQ/微信管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Qqandwechat qqandwechat) {
        return toAjax(qqandwechatService.insertQqandwechat(qqandwechat));
    }

    /**
     * 修改危险QQ/微信管理
     */
    @RequiresPermissions("system:qqandwechat:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Qqandwechat qqandwechat = qqandwechatService.selectQqandwechatById(id);
        mmap.put("qqandwechat", qqandwechat);
        return prefix + "/edit";
    }

    /**
     * 修改保存危险QQ/微信管理
     */
    @RequiresPermissions("system:qqandwechat:edit")
    @Log(title = "危险QQ/微信管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Qqandwechat qqandwechat) {
        return toAjax(qqandwechatService.updateQqandwechat(qqandwechat));
    }

    /**
     * 删除危险QQ/微信管理
     */
    @RequiresPermissions("system:qqandwechat:remove")
    @Log(title = "危险QQ/微信管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(qqandwechatService.deleteQqandwechatByIds(ids));
    }


    //移动端添加接口
    @PostMapping("/myadd")
    @ResponseBody
    public AjaxResult myadd(@RequestParam("account") String account,
                            @RequestParam("classify") String classify) {
        Qqandwechat qqandwechat = new Qqandwechat();
        qqandwechat.setAccount(account);
        qqandwechat.setClassify(classify);
        qqandwechatService.insertQqandwechat(qqandwechat);
        return success();
    }
    //移动端查询接口
    @PostMapping("/mygetitem")
    @ResponseBody
    public AjaxResult myget(@RequestParam("account") String account){
        Qqandwechat qqandwechat = new Qqandwechat();
        qqandwechat.setAccount(account);
        qqandwechatService.selectQqandwechatList(qqandwechat);
        return success();
    }
}
